package com.springcloud.market.order.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class OrderTimeoutSender {
    private final StreamBridge streamBridge;
    private static final String DELAY_LEVEL= "3";
    public OrderTimeoutSender(StreamBridge streamBridge){
        this.streamBridge =streamBridge;
    }
    public void sendOrderTimeoutMessage(String orderId){
        log.info("尝试发送订单超时消息，订单ID：" + orderId);
        boolean sent = streamBridge.send(
                "orderCancelProducer-out-0",
                MessageBuilder.withPayload(orderId)
                        .setHeader("DELAY", DELAY_LEVEL)
                        .build());
        if (sent) {
            log.info("订单超时消息发送成功，订单ID：" + orderId);
        } else {
            log.error("订单超时消息发送失败，订单ID：" + orderId);
        }

    }

}
